#!/bin/sh

I2C_BUS=${I2C_BUS:-14}
I2C_SA=${I2C_SA:-0x38}
I2C_REG=${I2C_REG:-0x0f}

usage() {
	echo "checkpoint CMD"
	echo ""
	echo "CMD List:"
	echo "  start      - Execution block started (0x01)"
	echo "  pause      - Pausing execution block (0x07)"
	echo "  resume     - Resumed execution block (0x08)"
	echo "  complete   - Completing execution block (0x09)"
}

do_start() {
	echo "Start Timer i2c-${I2C_BUS}[${I2C_SA}]@${I2C_REG}"
	i2cset -y ${I2C_BUS} ${I2C_SA} ${I2C_REG} 0x01
}

do_pause() {
	echo "Pause Timer i2c-${I2C_BUS}[${I2C_SA}]@${I2C_REG}"
	i2cset -y ${I2C_BUS} ${I2C_SA} ${I2C_REG} 0x07
}

do_resume() {

	echo "Pause Timer i2c-${I2C_BUS}[${I2C_SA}]@${I2C_REG}"
	i2cset -y ${I2C_BUS} ${I2C_SA} ${I2C_REG} 0x08

}

do_complete() {
	echo "Complete Timer i2c-${I2C_BUS}[${I2C_SA}]@${I2C_REG}"
	i2cset -y ${I2C_BUS} ${I2C_SA} ${I2C_REG} 0x09
}

if [ $# -lt 1 ]
then
	usage
	exit 1
fi

subcmd=$1
shift

case $subcmd in
	start)
		do_start
		;;
	pause)
		do_pause
		;;
	resume)
		do_resume
		;;
	complete)
		do_complete
		;;
	-h|--help|*)
		usage
		;;
esac
